package com.wn.servlet;

import com.alibaba.fastjson.JSON;
import com.wn.bean.Owner;
import com.wn.bean.PageVo;
import com.wn.service.OwnerService;
import com.wn.service.impl.OwnerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 *
 */
@WebServlet("/owner/page")
public class OwnerPageServlet extends HttpServlet {

    private OwnerService ownerService = new OwnerServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //回写的数据设置 编码格式
        resp.setContentType("text/html;charset=utf-8");

        //处理请求
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");

        //查询数据中的数据
        PageVo pageVo = ownerService.page(currentPage,pageSize);

        //使用json框架 可以直接把java对象转成 json 字符串
        String jsonString = JSON.toJSONString(pageVo);
        resp.getWriter().write(jsonString);
    }

}
